<template>
  <div>
    <article>
      <h2 style="text-align: center">{{ daily?.title }}</h2>
      <h4 class="subtitle">
        <span>作者：{{ daily?.author!.nickName }}</span>
        <span>发布时间:{{ daily?.createTime }}</span>
        <template v-if="daily?.lastAuthor != null">
          <span>最后编辑作者：{{ daily?.lastAuthor!.nickName }}</span>
          <span>最后修改时间:{{ daily?.updateTime }}</span>
        </template>
      </h4>
      <el-divider />
      <div v-html="daily?.content"></div>
    </article>
  </div>
</template>

<script setup lang="ts">
import Request from '@/api/request/request';
import urls from '@/api/request/urls';
import type { ResponseData } from '@/types/interface/base_interface';
import type { Daily } from '@/types/interface/sys_interface';
import { onMounted, ref } from 'vue';

import { useRoute } from 'vue-router';
const route = useRoute();
const dailyId = ref();
const daily = ref<Daily>();

onMounted(async () => {
  dailyId.value = route.query.dailyId;
  if (typeof dailyId.value !== 'undefined' && dailyId.value.length > 0) {
    const resData: ResponseData = await new Request(`${urls.API_URL_BACKSTAGE_DAILYT_MANAGE}/${dailyId.value}`).get();
    if (resData.success) {
      daily.value = resData.data;
    }
  }
});
</script>

<style scoped>
.subtitle {
  text-align: center;
  span {
    margin-left: 20px;
  }
}
</style>
